package com.beep.erp.model.stockIn;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.beep.erp.R;
import com.beep.erp.common.bean.PurchaseListBean;
import com.beep.erp.common.bean.StockInListBean;
import com.beep.erp.common.utils.TimeUtils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 作者 by Jolly on 2018/8/25.
 */

public class StockInListAdapter extends RecyclerView.Adapter<StockInListAdapter.PurchaseViewHolder> {


    private Context mContext;
    private LayoutInflater mLayoutInflater;
    private OnItemClickLitener mOnItemClickLitener;
    private ArrayList<StockInListBean.BizStockInVoListBean> mListBeen;
    private String goodStatus;

    public StockInListAdapter(Context context, ArrayList<StockInListBean.BizStockInVoListBean> mPurchaseListBean) {
        mContext = context;
        this.mListBeen = mPurchaseListBean;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    public void setOnItemClickLitener(OnItemClickLitener onItemClickLitener) {
        mOnItemClickLitener = onItemClickLitener;
    }

    @Override
    public PurchaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new PurchaseViewHolder(mLayoutInflater.inflate(R.layout.item_stock_in_list, parent, false));
    }

    @Override
    public void onBindViewHolder(PurchaseViewHolder holder, int position) {
        holder.tvStockInId.setText(mListBeen.get(position).getStockInCode());
        holder.tvStockInName.setText("创建人:" + mListBeen.get(position).getCreateByName());
        holder.tvTime.setText(TimeUtils.milliseconds2String(mListBeen.get(position).getStockInDate(), new SimpleDateFormat("yyyy-MM-dd")));

        if (mOnItemClickLitener != null) {
            holder.itemView.setOnClickListener(v -> {
                mOnItemClickLitener.onItemClick(v, position);
            });
        }
    }

    @Override
    public int getItemCount() {
        return mListBeen.size();
    }

    public class PurchaseViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_stock_in_id)
        TextView tvStockInId;
        @BindView(R.id.tv_stock_in_name)
        TextView tvStockInName;
        @BindView(R.id.tv_time)
        TextView tvTime;
        @BindView(R.id.rl_goods_msg)
        RelativeLayout rlGoodsMsg;
        @BindView(R.id.view_line)
        View viewLine;

        public PurchaseViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface OnItemClickLitener {
        void onItemClick(View view, int position);

    }
}
